/*
 * JANN - a Java toolkit for creating arbitrary Artificial Neural Networks.
 * 
 * Copyright (c) 2009 Matthijs Snel
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package net.jann.ui;
import java.awt.Color;
import java.awt.event.MouseEvent;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.List;

import org.jhotdraw.draw.AttributeKeys;
import org.jhotdraw.draw.DragTracker;
import org.jhotdraw.draw.Figure;


public class NeuronDragTracker extends DragTracker {

	protected List<Figure> highlighted;
	private static final long serialVersionUID = 6200718171266200301L;

	public NeuronDragTracker(Figure figure) {
		super(figure);
		highlighted = new ArrayList<Figure>();
	}
	
	@Override
	public void mouseClicked(MouseEvent evt) {
		super.mouseClicked(evt);
		if ( anchorFigure instanceof NeuronFigure )
			highlightFromNeuron( (NeuronFigure) anchorFigure );
		else if ( anchorFigure instanceof LinkFigure )
			highlightFromLink( (LinkFigure) anchorFigure );
	}
	
	void handleMultiClick( MouseEvent evt ) {
		
	}
	
	protected void highlightFromLink( LinkFigure focusFig ) {
		highlight(focusFig);
		highlight(focusFig.getStartFigure());
		highlight(focusFig.getEndFigure());
		getView().getComponent().repaint();
	}
	
	protected void highlightFromNeuron( NeuronFigure focusFig ) {
		highlight(focusFig);
		for ( LinkFigure f : focusFig.getIncoming() ) {
			highlight(f);
			highlight(f.getStartFigure());
		}
		for ( LinkFigure f : focusFig.getOutgoing() ) {
			highlight(f);
			highlight(f.getEndFigure());
		}
		getView().getComponent().repaint();
	}
	
	protected void highlight( Figure fig ) {
		AttributeKeys.STROKE_COLOR.basicSet(fig, Color.red);
		highlighted.add(fig);
	}

}
